﻿using STMS.BLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace STMS.STMSapp
{
    public partial class FrmLogin : Form
    {
        public FrmLogin()
        {
            InitializeComponent();
            panel.BackColor = Color.FromArgb(50, 255, 255, 255);
            panel1.BackColor = Color.FromArgb(70, 255, 255, 255);
            panel2.BackColor = Color.FromArgb(70, 255, 255, 255);

        }


        // 登录逻辑
        // 检查用户存在性 ui--bll--dal,   检查(select)
        // 检查结果, 存在-->登录成功,显示主界面   不存在,中断
        private void btnLogin_Click(object sender, EventArgs e)
        {
            string uName = tbUserName.Text;
            string uPwd = tbPassword.Text;
            UserBLL userBLL = new UserBLL();
            bool blLogin = userBLL.LoginSystem(uName, uPwd);
            if (blLogin)
            {
                // 登录成功, 显示系统页面逻辑
                FrmMain frmMain = new FrmMain();
                frmMain.Tag = uName;
                this.Hide();
                frmMain.Show();
                
            }
            else
            {
                MessageBox.Show("登陆失败，用户名或密码错误！");
            }
        }

        private void tbPassword_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter)
            {
                btnLogin_Click((object)sender, e);
            }
        }
    }

}
